package com.starfactory.customer.api;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.starfactory.customer.shared.dto.Result;
import com.starfactory.customer.table.deviceConfig.DeviceConfig;
import com.starfactory.customer.table.deviceConfig.DeviceConfigMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Slf4j
@Service
public class DeviceConfigDeteled {
    @Autowired private DeviceConfigMapper deviceConfigMapper;
    public Result<Boolean> deviceConfigDeteled (Long deviceConfigId){
        DeviceConfig deviceConfig = deviceConfigMapper.selectOne(new QueryWrapper<DeviceConfig>().eq("id", deviceConfigId));
        if (deviceConfig == null){
            return new Result<>(404, "设备阈值信息不存在", false);
        }
        deviceConfig.setCpuUsageThreshold(null);
        deviceConfig.setMemoryUsageThreshold(null);
        deviceConfig.setDiskUsage(null);
        deviceConfig.setNetworkInputUsage(null);
        deviceConfig.setNetworkOutputUsage(null);

        int updateResult = deviceConfigMapper.updateById(deviceConfig);
        log.info("更新结果: {}, deviceConfigId: {}", updateResult, deviceConfigId);
        if (updateResult > 0){
            return new Result<>(200, "设备阈值信息删除成功", true);
        }else {
            return new Result<>(500, "设备阈值信息删除失败", false);
        }
    }
}
